from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from geektime_0.app.wework.page.base_page import BasePage


class ContactPage(BasePage):

    def add_contact(self,name, phone):
        # 点击搜索输入框最右侧按钮
        self.find(AppiumBy.ID, "kv4").click()
        # 点击添加成员按钮
        self.find(AppiumBy.CSS_SELECTOR, '[text="添加成员"]').click()
        # 点击手动输入添加
        self.find(AppiumBy.CSS_SELECTOR, '[text="手动输入添加"]').click()
        # 输入姓名
        self.find(AppiumBy.ID, "buv").send_keys(name).click()
        # 输入手机号
        self.find(AppiumBy.ID, "hvk").send_keys(phone).click()
        # 取消勾选保存后自动发送邀请通知
        self.find(AppiumBy.ID, "hfi").click()
        # 点击保存按钮
        self.find(AppiumBy.CSS_SELECTOR, '[text="保存"]').click()
        # todo: 用显式等待
        WebDriverWait(self.driver, 10).until(expected_conditions.visibility_of_element_located((AppiumBy.ID, "kuf")))
        # 添加成员页面点击返回按钮
        self.find(AppiumBy.ID, "kuf").click()
        # 管理通讯录页面点击右上角的叉
        self.find(AppiumBy.ID, "kuz").click()

    def back(self):
        # 点击底部的消息
        self.find(AppiumBy.CSS_SELECTOR, '[text="消息"]').click()